"use strict";

const Service = require("egg").Service;

class rentingService extends Service {
  //列表查看
  async rentingList(pageIndex, pageSize) {
    const total = await this.app.mysql.select("renting");
    // console.log((pageIndex - 1) * pageSize * 1, pageIndex * pageSize * 1);
    const res = await this.app.mysql.select("renting", {
      // 搜索 post 表
      limit: Number(pageSize * 1), // 返回数据量
      offset: Number((pageIndex - 1) * pageSize * 1), // 数据偏移量
    });

    return { total, res };
  }
  // 添加
  async rentingAdd(name, word, region, mianji, price, time, flag) {
    const { app } = this;
    await app.mysql.insert("renting", {
      name: name,
      word: word,
      region: region,
      mianji: mianji,
      price: price,
      time: time,
      flag: flag,
    });
    return true;
  }
  // 删除
  async rentingDel(id) {
    const { app } = this;
    await app.mysql.delete("renting", {
      id: id,
    });
    return true;
  }
  // 编辑
  async rentingSet(obj) {
    const { app } = this;
    await app.mysql.update("renting", obj);
    return true;
  }
}
module.exports = rentingService;
